package com.oba.king.hospitalinfo.doctorinformation;

import java.util.List;

import com.oba.base.dao.BaseDao;
import com.oba.base.interfaces.IHsqlBuilder;
import com.oba.king.hospitalinfo.doccolinformation.DoccolCondition;
import com.oba.king.hospitalinfo.doccolinformation.DoccolInformation;
import com.oba.king.hospitalinfo.hospitalinformation.HospitalInformation;

public class DoctorInfoDao extends BaseDao {
	
	public IHsqlBuilder buildAll() {
		IHsqlBuilder sql = getSqlBuilder("from DoctorInfo doc");
		sql.addend("order by doc.doctorNm");
		return sql;
	}
	
	public IHsqlBuilder srchByConditon(String doctorName){
		IHsqlBuilder sql = getSqlBuilder("from DoctorInfo doc");
		sql.add("doc.doctorNm like ?", doctorName, "%", "%");
		sql.addend("order by doc.doctorNm");
		return sql;
	}
	
	public List<HospitalInformation> buildAllHospital() {
		return find("from HospitalInformation hospital");
	}
	
	public List<DoccolInformation> srchByHospital(HospitalInformation hosp){
		IHsqlBuilder sql = getSqlBuilder("from DoccolInformation docc");
		sql.add("docc.hospitalInformation = ?", hosp);
		return find(sql);		
	}
	
	// 模糊查询
	public IHsqlBuilder srchDoctorByCondition(DoctorCondition doctorCondition) {
		IHsqlBuilder sql = getSqlBuilder("from DoctorInfo doc");
		sql.add("doc.doctorNm like ?", doctorCondition.getDoctorNm().trim(), "%", "%");
//		sql.add("doc.workAddr like ?", doctorCondition.getWorkAddr().trim(), "%", "%");
		sql.add("doc.doccolInformation.sectionName like ?", doctorCondition.getSectionName().trim(), "%", "%");
		sql.add("doc.doccolInformation.hospitalInformation.documentId =?", doctorCondition.getDocumentId().trim());
		sql.add("doc.doccolInformation.hospitalInformation.hospitalName like ?", doctorCondition.getHospitalName().trim(), "%", "%");
		sql.add("doc.doccolInformation.hospitalInformation.hospitalCode =?", doctorCondition.getHospitalCode().trim());
		sql.addend("order by doc.doctorNm");
		return sql;
	}
}
